<?php
include dirname(__FILE__).'/../Control/AdminControl.cls.php';
$action = Get::getByKey('action');
$check = Get::getByKey('check');
$mydb = new DataBaseObject();
if ($action=='createnode')
{
	$act = array('Add'=>'新增','List'=>'列表','Edit'=>'编辑','Del'=>'删除','View'=>'查看');
	if ($check == 'check')
	{
		$i=0;		
		foreach($act as $key=>$v )
		{
			//echo count($mydb ->db->select('admins_node',array('names'=>$key.Get::getByKey('tableName'),'title'=>Get::getByKey('tableNameCN').'-'.$v,'remark'=>Get::getByKey('tableNameCN'))));
			if (count($mydb ->db->select('admins_node',array('names'=>$key.Get::getByKey('tableName'),'title'=>Get::getByKey('tableNameCN').'-'.$v,'remark'=>Get::getByKey('tableNameCN'))))==0)
				$i++;
		}		
		if ($i==0) echo "ok";
	}else{		
		foreach($act as $key=>$v )
		{
			$mydb ->db->delete('admins_node',array('names'=>$key.Get::getByKey('tableName')));
			$mydb ->db->insert('admins_node',array('names'=>$key.Get::getByKey('tableName'),'title'=>Get::getByKey('tableNameCN').'-'.$v,'status'=>1,'remark'=>Get::getByKey('tableNameCN'),'pid'=>0,'level'=>1));		
		}
		echo "ok";
	}
}else if($action=='createcontrol')
{
	$conStr = "";
	$tableName= Get::getByKey('tableName');
	if ($tableName=='') exit();
	if ($check == 'check')
	{
		$conStr = FileSystem::readFile("../Control/AdminControl.cls.php");
		$datarr = split('//---'.$tableName.'---//',$conStr);		
		if (count($datarr)>1) echo "ok";
	}else{
		$conStr = FileSystem::readFile("../Control/AdminControl.cls.php");
		$datarr = split('//---'.$tableName.'---//',$conStr);
		if (count($datarr)==1)
		{			
			$temStr  = FileSystem::readFile("../Tool/TemplateControl.php");
			$temStr = str_replace('[tableName]',$tableName,$temStr);			
			$conStr = str_replace('//---end---//',$temStr,$conStr);	
			FileSystem::saveData("../Control/AdminControl.cls.php",$conStr);	
			echo "ok";
		}		
	}
}
?>
